<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div class="row">
        <div class="col-md-12">
            <button id="showNoti">显示通知</button>
        </div>
    </div>
    <script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
    <script>
        /*  $(function () {
                    $("#showNoti").click(function () {
                        if (!window.Notification) {
                            alert("浏览器不支持通知！");
                        }
                        console.log(window.Notification.permission);　　　　　　　　　
                        if (window.Notification.permission != 'granted') {　　
                            Notification.requestPermission(function (status) {
                                //status是授权状态，如果用户允许显示桌面通知，则status为'granted'
                                console.log('status: ' + status);
                                //permission只读属性:
                                //  default 用户没有接收或拒绝授权 不能显示通知
                                //  granted 用户接受授权 允许显示通知
                                //  denied  用户拒绝授权 不允许显示通知
                                var permission = Notification.permission;
                                console.log('permission: ' + permission);
                            });
                        }
                        var n = new Notification("您有一条消息！", {
                            "icon": "",
                            "body": "您一分钟后将有好运气"
                        });
                        n.onshow = function () {
                            console.log("显示通知");
                            setTimeout(function () {
                                n.close()
                            }, 2000);
                        };
                        n.onclick = function () {
                            alert("打开相关视图");
                            window.open("/Home/about");
                            n.close();
                        };
                        n.onclose = function () {
                            console.log("通知关闭");
                        };
                        n.onerror = function (e) {
                            console.log('产生错误'); //do something useful  
                        };
                    });
                }); */
        function notifyMe() {
            // Let's check if the browser supports notifications
            if (!("Notification" in window)) {
                console.log("This browser does not support desktop notification");
            }

            // Let's check whether notification permissions have alredy been granted
            else if (Notification.permission === "granted") {
                // If it's okay let's create a notification
                var notification = new Notification("Hi there!");
            }

            // Otherwise, we need to ask the user for permission
            else if (Notification.permission !== 'denied' || Notification.permission === "default") {
                Notification.requestPermission(function (permission) {
                    // If the user accepts, let's create a notification
                    if (permission === "granted") {
                        var notification = new Notification("Hi there!");
                    }
                });
            }

            // At last, if the user has denied notifications, and you 
            // want to be respectful there is no need to bother them any more.
        }
        notifyMe();
    </script>
</body>

</html>